package admin

import (
	"last/app/models"
	"last/pkg/database"
)

type Socials struct {
	models.BaseModel
	Title string `json:"title"`
	Icon  string `json:"icon"`
	Href  string `json:"href"`
	models.CommonTimestampsField
}

// Stroe 新增
func (s Socials) Stroe(data interface{}) bool {
	result := database.DB.Model(Socials{}).Create(data)
	return result.RowsAffected == 1
}

// List 列表
func (s Socials) List(page, pageSize int, where map[string]interface{}) (error, int64, interface{}) {
	var data []Socials
	var total int64
	query := database.DB.Model(Socials{})
	if where["title"] != "" {
		query.Where("title = ?", where["title"])
	}
	query.Count(&total)
	return query.Order("id DESC").Find(&data).Error, total, data
}

// Show 详情
func (s Socials) Show(id string, data interface{}) error {
	return database.DB.Model(Socials{}).Where("id=?", id).Find(data).Error
}

// Edit 更新
func (s *Socials) Edit(id int, data interface{}) error {
	return database.DB.Model(Socials{}).Where("id=?", id).Updates(data).Error
}

// Remove 删除
func (s *Socials) Remove(id string, data interface{}) error {
	return database.DB.Model(Socials{}).Where("id=?", id).Delete(data).Error
}
